package com.huiyeji.dynamic.core.bean;

import com.huiyeji.dynamic.core.annotations.DynamicBean;
import com.huiyeji.dynamic.core.annotations.DynamicMethod;

import java.math.BigDecimal;
import java.util.Objects;

@DynamicBean("integer")
public class DynamicInteger {

    @DynamicMethod
    public Integer add(Integer a, Integer b) {
        return a + b;
    }

    @DynamicMethod
    public Integer sub(Integer a, Integer b) {
        return a - b;
    }

    @DynamicMethod
    public Integer mul(Integer a, Integer b) {
        return a * b;
    }

    @DynamicMethod
    public Integer div(Integer a, Integer b) {
        return a / b;
    }

    @DynamicMethod
    public boolean gt(Integer a, Integer b) {
        return a > b;
    }

    @DynamicMethod
    public boolean lt(Integer a, Integer b) {
        return a < b;
    }

    @DynamicMethod
    public boolean eq(Integer a, Integer b) {
        return Objects.equals(a, b);
    }

    @DynamicMethod
    public boolean ne(Integer a, Integer b) {
        return !eq(a, b);
    }

    @DynamicMethod
    public boolean gte(Integer a, Integer b) {
        return a >= b;
    }

    @DynamicMethod
    public boolean lte(Integer a, Integer b) {
        return a <= b;
    }

    @DynamicMethod
    public Integer of(Object value) {
        if (value instanceof Integer){
            return (Integer) value;
        } else if (value instanceof String){
            return Integer.valueOf((String) value);
        } else {
            throw new IllegalArgumentException("value must be Integer or String");
        }
    }
}
